package middleware

import (
	"fmt"
	"net/http"
	"user-profile/pkg"
)

type UserAgentMiddleware struct {
}

func NewUserAgentMiddleware() *UserAgentMiddleware {
	return &UserAgentMiddleware{}
}

func (m *UserAgentMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		// TODO generate middleware implement function, delete after code implementation
		get := r.Header.Get("token")
		i := pkg.Get(get)
		fmt.Println(123)
		fmt.Println(i["id"].(string))
		fmt.Println(123)
		r.ParseForm()
		// Passthrough to next handler if need
		r.Form.Set("userId", i["id"].(string))

		next(w, r)
	}
}
